package sis.utiltest;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-07-27 14:39
 * @notify
 * @version 1.0
 */

import junit.framework.TestCase;
import org.omg.CORBA.PUBLIC_MEMBER;
import sis.util.PasswordGenerator;

import java.util.Random;

public class PasswordGeneratorTest extends TestCase {
    public void testGeneratePassword() {
        PasswordGenerator generator = new PasswordGenerator();
        generator.setRandom(new MockRandom('A'));
        assertEquals("ABCDEFGH", generator.generatePassword());

        generator.setRandom(new MockRandom('C'));
        assertEquals("CDEFGHIJ", generator.generatePassword());
    }

    class MockRandom extends Random{
        private int i;
        MockRandom(char startCharValue){
            i = startCharValue - PasswordGenerator.LOW_END_PASSWORD_CHAR;
        }
        protected int next(int bits){
            return i++;
        }
    }
}
